﻿@inherits AdminCompontentBase

<div class="full-height flex-column">
    <MCard Class="flex-height-auto d-flex flex-column justify-center align-center">
        <div class="grid grid-2">
            <div class="item">
                <MHover Context="hoverContext" ValueChanged="(v)=>HandleHoverChanged(v,ReceiverTypes.Assign)">
                    <MCard @attributes="hoverContext.Attrs" Class="@($"d-flex flex-column justify-center align-center {(hoverContext.Hover ? "primary" : "fill-background")}")"
                           OnClick="()=>HandleReceiverType(ReceiverTypes.Assign)">
                        @if (hoverContext.Hover)
                        {
                            <SIcon Size=60 Color="fill">mdi-account-supervisor-circle</SIcon>
                            <div class="h6 pt-11 fill--text">@T("DisplayName.ReceiverType.Assign")</div>
                        }
                        else if (Value == ReceiverTypes.Assign)
                        {
                            <SIcon Size=60 Color="primary">mdi-account-supervisor-circle</SIcon>
                            <div class="h6 pt-11 primary--text">@T("DisplayName.ReceiverType.Assign")</div>
                        }
                        else
                        {
                            <SIcon Size=40 Color="emphasis2">mdi-account-supervisor-circle</SIcon>
                            <div class="h6 pt-14 regular--text">@T("DisplayName.ReceiverType.Assign")</div>
                        }
                    </MCard>
                </MHover>
            </div>
            <div class="item">
                <MHover Context="hoverContext" ValueChanged="(v)=>HandleHoverChanged(v,ReceiverTypes.Broadcast)">
                    <MCard @attributes="hoverContext.Attrs" Class="@($"d-flex flex-column justify-center align-center {(hoverContext.Hover ? "primary" : "fill-background")}")"
                           OnClick="()=>HandleReceiverType(ReceiverTypes.Broadcast)">
                        @if (hoverContext.Hover)
                        {
                            <SIcon Size=60 Color="fill">mdi-email</SIcon>
                            <div class="h6 pt-11 fill--text">@T("DisplayName.ReceiverType.Broadcast")</div>
                        }
                        else if (Value == ReceiverTypes.Broadcast)
                        {
                            <SIcon Size=60 Color="primary">mdi-email</SIcon>
                            <div class="h6 pt-11 primary--text">@T("DisplayName.ReceiverType.Broadcast")</div>
                        }
                        else
                        {
                            <SIcon Size=40 Color="emphasis2">mdi-email</SIcon>
                            <div class="h6 pt-14 regular--text">@T("DisplayName.ReceiverType.Broadcast")</div>
                        }
                    </MCard>
                </MHover>
            </div>
        </div>
    </MCard>
</div>

@code {
    [Parameter]
    public ReceiverTypes Value { get; set; }

    [Parameter]
    public EventCallback<ReceiverTypes> OnClick { get; set; }

    private ReceiverTypes _hoverType;

    private async Task HandleReceiverType(ReceiverTypes receiverType)
    {
        _hoverType = default;

        if (OnClick.HasDelegate)
        {
            await OnClick.InvokeAsync(receiverType);
        }
        else
        {
            Value = receiverType;
        }
    }

    private void HandleHoverChanged(bool val, ReceiverTypes hoverType)
    {
        _hoverType = val ? hoverType : default;
    }
}
